<template>
  <page-header-wrapper>
    <GlobalSearch :list="searchList" @search="handleSearch" @reset="handleReset"> </GlobalSearch>
    <a-card :bordered="false">
      <div class="text-right m-b-24">
        <y-button slot="action" type="warning" icon="plus" @click="visibleImport = true">批量导入</y-button>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
        :scroll="{ x: true }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record)">查看</y-button>
        </div>
      </s-table>
    </a-card>
    <detail :visible.sync="visibleDetail" :data.sync="contract"></detail>
    <import-excel :visible.sync="visibleImport"></import-excel>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getContractRentAccount } from '@/api/followUpManagement'
import detail from './components/detail.vue'
import importExcel from './components/import.vue'
import moment from 'moment'
export default {
  components: {
    STable,
    Ellipsis,
    detail,
    importExcel
  },
  data () {
    return {
      contract: {},
      visibleSign: false,
      visibleDetail: false,
      visibleImport: false,
      queryParam: {
        strContent: {}
      },
      searchList: [
        {
          label: '项目名称',
          fields: 'projectName',
          type: 'input',
          props: {
            placeholder: '请输入项目名称'
          }
        },
        {
          label: '签订人姓名',
          fields: 'name',
          type: 'input',
          props: {
            placeholder: '请输入合同签订人姓名'
          }
        },
        {
          label: '证件号码',
          fields: 'IDCard',
          type: 'input',
          props: {
            placeholder: '请输入证件号码'
          }
        },
        {
          label: '租赁日期',
          fields: 'zlDate',
          type: 'range',
          props: {
            valueFormat: 'YYYY-MM-DD'
          }
        },
        {
          label: '合同签订时间',
          fields: 'signDate',
          type: 'date',
          props: {
            valueFormat: 'YYYY-MM-DD'
          }
        },
        {
          label: '低保收入减免时间',
          fields: 'dbdsrjmData',
          type: 'date',
          props: {
            valueFormat: 'YYYY-MM-DD'
          }
        },
        {
          label: '租金减免时间',
          fields: 'zjjmData',
          type: 'date',
          props: {
            valueFormat: 'YYYY-MM-DD'
          }
        },
        {
          label: '租金日期',
          fields: 'rentDate',
          type: 'range',
          props: {
            valueFormat: 'YYYY-MM-DD'
          }
        }
      ],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'UnitName'
        },
        {
          title: '合同签订人姓名',
          align: 'center',
          dataIndex: 'Name'
        },
        {
          title: '证件号码',
          align: 'center',
          dataIndex: 'IDCard'
        },
        {
          title: '房屋信息',
          align: 'center',
          dataIndex: 'EAddress',
          customRender: (text) => <ellipsis length={28}>{text || '/'}</ellipsis>
        },
        {
          title: '租赁期限开始时间',
          align: 'center',
          dataIndex: 'StartDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '租赁期限结束时间',
          align: 'center',
          dataIndex: 'EndDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '月租金',
          align: 'center',
          dataIndex: 'RentMonth',
          customRender: (text) => `￥${text}`
        },
        {
          title: '保证金(押金)',
          align: 'center',
          dataIndex: 'Margin',
          customRender: (text) => (text ? `￥${text}` : '/')
        },
        {
          title: '合同签订日期',
          align: 'center',
          dataIndex: 'SignDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '低保低收入减免金额',
          align: 'center',
          dataIndex: 'ReductionMoney',
          customRender: (text) => (text ? `￥${text}` : '/')
        },
        {
          title: '低保低收入减免执行时间',
          align: 'center',
          dataIndex: 'ReductionData',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '租金减免金额',
          align: 'center',
          dataIndex: 'RentReliefMoney',
          customRender: (text) => (text ? `￥${text}` : '/')
        },
        {
          title: '租金减免执行时间',
          align: 'center',
          dataIndex: 'RentReliefDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '租金起始时间',
          align: 'center',
          dataIndex: 'RentStartTime',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '租金截止时间',
          align: 'center',
          dataIndex: 'RentEndTime',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD') : '/')
        },
        {
          title: '缴纳租金月数',
          align: 'center',
          dataIndex: 'RentPaymentMonth',
          customRender: (text) => (text ? `${text}月` : '/')
        },
        {
          title: '应收租金',
          align: 'center',
          dataIndex: 'RentPayable',
          customRender: (text) => (text ? `￥${text}` : '/')
        },
        {
          title: '收缴金额',
          align: 'center',
          dataIndex: 'CollectionMoney',
          customRender: (text) => (text ? `￥${text}` : '/')
        },
        {
          title: '未足额收取原因',
          align: 'center',
          dataIndex: 'NoCollectionReason',
          customRender: (text) => (text ? <ellipsis length={28}>{text}</ellipsis> : '/')
        },
        {
          title: '操作',
          align: 'center',
          width: '8px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getContractRentAccount(requestParameters).then((res) => res)
      }
    }
  },
  methods: {
    handleSearch (values) {
      const { zlDate, rentDate } = values
      if (!this.$isEmpty(zlDate)) {
        values.zlStartTime = zlDate[0]
        values.zlEndTime = zlDate[1]
      }
      if (!this.$isEmpty(rentDate)) {
        values.rentStartTime = rentDate[0]
        values.rentEndTime = rentDate[1]
      }
      delete values.zlDate
      delete values.rentDate
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset () {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh (refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleDetail (record) {
      this.contract = record
      this.visibleDetail = true
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .ant-table-scroll td {
  white-space: nowrap;
}
</style>
